import apiClient from './client'
import type { User, RegisterData } from '@/types'
import type { PageInfo } from '@/types'

export const userService = {
  // ===== 用户管理模块 (/api/v1/users) =====

  // 获取所有用户列表
  getAllUsers: () => apiClient.get<User[]>('/api/v1/users/list'),

  // 根据ID获取单个用户信息
  getUserDetail: (userId: number) => apiClient.get<User>(`/api/v1/users/detail/${userId}`),

  // 新增一个用户
  addUser: (userData: RegisterData) => apiClient.post<User>('/api/v1/users/add', userData),

  // 更新一个用户信息
  updateUser: (userData: Partial<User>) => apiClient.post<User>('/api/v1/users/update', userData),

  // 根据ID删除一个用户
  deleteUser: (userId: number) => apiClient.post('/api/v1/users/delete', { userId }),

  // 切换用户启用/禁用状态
  toggleUserStatus: (id: number, status: number) =>
    apiClient.post('/api/v1/users/toggle-status', { id, status }),

  // 分页并按条件获取用户列表
  getUsersListPage: (
    pageNum: number = 1,
    pageSize: number = 10,
    query?: Record<string, string | number | boolean | null | undefined>,
  ) =>
    apiClient.get<PageInfo<User>>('/api/v1/users/list/page', {
      params: { pageNum, pageSize, ...query },
    }),
}

export default userService
